<script>
	import ipConfig from '@/utils/ipconfig.js'
	import { lastestVersion } from '@/common/api/profile.js'
	export default {
		onLaunch: function() {
			let appVersion = ''
			uni.getSystemInfo({
				success: function(e) {
					appVersion = e.platform;
				}
			})
			plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => {
				lastestVersion().then( res => {	//此处为访问后台是否有更新
					if (res.data.versionNum > parseInt(wgtinfo.versionCode)) {
						uni.showModal({
							title: "发现新版本",
							confirmText:'立即更新',
							cancelText:'稍后进行',
							success: sucRes => {
								if (sucRes.confirm) {
									if(appVersion == 'android'){
										uni.showLoading({
											title: '新版本下载中，请稍等',
											mask: true,
										})
										uni.downloadFile({
											url: ipConfig.ip + 'admin/sysappversion/getLastestVersionUrl',
											success: data => {
												if (data.statusCode === 200) {
													uni.hideLoading();
													plus.runtime.install(data.tempFilePath, {
														force: true 
													}, function() {
														plus.runtime.restart();  
													});  
												 }  
											},
										})
									}
								}else if (sucRes.cancel) {
									uni.getSystemInfo({
										success: function (res) {
											if(res.platform == 'android'){
												plus.runtime.quit();
											}else{
												plus.ios.import("UIApplication").sharedApplication().performSelector("exit");    
											}    
									}});
								}
							}
						})
					}
				})
			})
		},
		onShow: function() {
			
		},
		onHide: function() {
			
		}
	}
</script>

<style>
	/*每个页面公共css */
	@import 'common/style/style.less';
	/* @import 'common/style/uni.css'; */
	@import 'static/icon/iconfont.css';
</style>
